package spring.cloud.tasks.common.zookeeper;

import org.apache.commons.lang.StringUtils;

import java.util.Comparator;

public class TaskItemComparator implements Comparator<String> { //
    public int compare(String leftString, String rightString) {//
        if (StringUtils.isNumeric(leftString) && StringUtils.isNumeric(rightString)) {//
            int leftIntString = Integer.parseInt(leftString);//
            int rightIntString = Integer.parseInt(rightString);//
            if (leftIntString == rightIntString) {//
                return 0;
            } else if (leftIntString > rightIntString) {//
                return 1;
            } else {
                return -1;
            }
        } else {
            return leftString.compareTo(rightString);
        }
    }
}
